<?php
define('DB_DSN','mysql:dbname=crm;charset=UTF8');
define('DB_USER','root');
define('DB_PASSWORD','');

function dbSelect($mysql,$data=null){
	$pdo=new PDO(DB_DSN,DB_USER,DB_PASSWORD);
	$star=$pdo->prepare($mysql);
	$star->execute($data);
	return $star->fetch(PDO::FETCH_NAMED);
}
function dbSelectAll($mysql,$data=null){
	$pdo=new PDO(DB_DSN,DB_USER,DB_PASSWORD);
	$star=$pdo->prepare($mysql);
	$star->execute($data);
	return $star->fetchAll(PDO::FETCH_NAMED);
}
function dbSelectPage($mysql,$pageNum,$pageSize){
	$offset = ($pageNum-1)*$pageSize;
	if(empty($pageNum) || empty($pageSize)){
		$mysql2 = "";
	}else{
		$mysql2 = " limit $offset,$pageSize";
	}
	$pdo=new PDO(DB_DSN,DB_USER,DB_PASSWORD);
	$star=$pdo->prepare($mysql.$mysql2);
	$star->execute(array());
	return $star->fetchAll(PDO::FETCH_NAMED);
}
function dbInsert($mysql,$data=null){
	$pdo=new PDO(DB_DSN,DB_USER,DB_PASSWORD);
	$star=$pdo->prepare($mysql);
	return $star->execute($data);
}
function dbUpdate($mysql,$data=null){
	$pdo=new PDO(DB_DSN,DB_USER,DB_PASSWORD);
	$star=$pdo->prepare($mysql);
	return $star->execute($data);
}
function dbDelete($mysql,$data=null){
	$pdo=new PDO(DB_DSN,DB_USER,DB_PASSWORD);
	$star=$pdo->prepare($mysql);
	return $star->execute($data);
}
function pageNum($pageNum){
	if(empty($pageNum)||$pageNum < 1||!is_numeric($pageNum)){
		$pageNum = 1;
	}
	return $pageNum;
}





